package com.yl.project.lvyou.booking.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yl.framework.aspectj.lang.annotation.Log;
import com.yl.framework.aspectj.lang.enums.BusinessType;
import com.yl.project.lvyou.booking.domain.TicketBooking;
import com.yl.project.lvyou.booking.service.ITicketBookingService;
import com.yl.framework.web.controller.BaseController;
import com.yl.framework.web.domain.AjaxResult;
import com.yl.common.utils.poi.ExcelUtil;
import com.yl.framework.web.page.TableDataInfo;

/**
 * 门票预订Controller
 * 
 * @author yl
 * @date 2025-03-15
 */
@Controller
@RequestMapping("/lvyou/booking")
public class TicketBookingController extends BaseController
{
    private String prefix = "scenemanager/booking";

    @Autowired
    private ITicketBookingService ticketBookingService;

    @RequiresPermissions("scenemanager:booking:view")
    @GetMapping()
    public String booking()
    {
        return prefix + "/booking";
    }

    /**
     * 查询门票预订列表
     */
    @RequiresPermissions("scenemanager:booking:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TicketBooking ticketBooking)
    {
        startPage();
        List<TicketBooking> list = ticketBookingService.selectTicketBookingList(ticketBooking);
        return getDataTable(list);
    }

    /**
     * 导出门票预订列表
     */
    @RequiresPermissions("scenemanager:booking:export")
    @Log(title = "门票预订", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TicketBooking ticketBooking)
    {
        List<TicketBooking> list = ticketBookingService.selectTicketBookingList(ticketBooking);
        ExcelUtil<TicketBooking> util = new ExcelUtil<TicketBooking>(TicketBooking.class);
        return util.exportExcel(list, "booking");
    }

    /**
     * 新增门票预订
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存门票预订
     */
    @RequiresPermissions("scenemanager:booking:add")
    @Log(title = "门票预订", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TicketBooking ticketBooking)
    {
        return toAjax(ticketBookingService.insertTicketBooking(ticketBooking));
    }

    /**
     * 修改门票预订
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TicketBooking ticketBooking = ticketBookingService.selectTicketBookingById(id);
        mmap.put("ticketBooking", ticketBooking);
        return prefix + "/edit";
    }

    /**
     * 修改保存门票预订
     */
    @RequiresPermissions("scenemanager:booking:edit")
    @Log(title = "门票预订", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TicketBooking ticketBooking)
    {
        return toAjax(ticketBookingService.updateTicketBooking(ticketBooking));
    }

    /**
     * 删除门票预订
     */
    @RequiresPermissions("scenemanager:booking:remove")
    @Log(title = "门票预订", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketBookingService.deleteTicketBookingByIds(ids));
    }
}
